package cn.tedu.oa_system.controller;

import cn.tedu.oa_system.base.json_result.ResultDataDto;
import cn.tedu.oa_system.base.json_result.ResultDto;
import cn.tedu.oa_system.pojo.Attends;
import cn.tedu.oa_system.pojo.in.FindLikeKeyIn;
import cn.tedu.oa_system.pojo.in.PageIn;
import cn.tedu.oa_system.pojo.vo.AttendsVO;
import cn.tedu.oa_system.service.AttendsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author MW
 * @Description 考勤控制器
 * @CreateDate 2023/3/1
 */
@Slf4j
@RestController
@RequestMapping(value = "/attends")
public class AttendsController {

    @Autowired
    private AttendsService attendsService;

    @GetMapping("/signin")
    private ResultDto<AttendsVO> signIn(){
        return attendsService.signIn();
    }

    @PostMapping("/listofall")
    private ResultDataDto<AttendsVO> listOfAll(@RequestBody PageIn pageIn){
        if (pageIn.getCurrent()==null||pageIn.getCurrent()<=0L){
            pageIn.setCurrent(1L);
        }
        if (pageIn.getSize()==null||pageIn.getCurrent()<=2L){
            pageIn.setSize(10L);
        }
        return attendsService.listOfAll(pageIn);
    }

    @PostMapping("/findlikekeyofall")
    private ResultDataDto<AttendsVO> findLikeKeyOfAll(@RequestBody FindLikeKeyIn likeKeyIn){
        if (likeKeyIn.getCurrent()==null||likeKeyIn.getCurrent()<=0L){
            likeKeyIn.setCurrent(1L);
        }
        if (likeKeyIn.getSize()==null||likeKeyIn.getCurrent()<=2L){
            likeKeyIn.setSize(10L);
        }
        return attendsService.findLikeKeyOfAll(likeKeyIn);
    }

    @PostMapping("/listofself")
    private ResultDataDto<Attends> listOfSelf(@RequestBody PageIn pageIn){
        if (pageIn.getCurrent()==null||pageIn.getCurrent()<=0L){
            pageIn.setCurrent(1L);
        }
        if (pageIn.getSize()==null||pageIn.getCurrent()<=2L){
            pageIn.setSize(10L);
        }
        return attendsService.listOfSelf(pageIn);
    }

    @PostMapping("/findlikekeyofself")
    private ResultDataDto<AttendsVO> findLikeKeyOfSelf(@RequestBody FindLikeKeyIn likeKeyIn){
        if (likeKeyIn.getCurrent()==null||likeKeyIn.getCurrent()<=0L){
            likeKeyIn.setCurrent(1L);
        }
        if (likeKeyIn.getSize()==null||likeKeyIn.getCurrent()<=2L){
            likeKeyIn.setSize(10L);
        }
        return attendsService.findLikeKeyOfSelf(likeKeyIn);
    }
}
